{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "subscription_key = \"4f253843772f42e89e959977f6149561\"\n",
    "assert subscription_key"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'faceId': '5d9fcdd4-e908-44ed-8aec-180fd599cb2b',\n",
       "  'faceRectangle': {'top': 128, 'left': 237, 'width': 69, 'height': 69},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': -1.5, 'roll': -4.1, 'yaw': -4.4},\n",
       "   'gender': 'male',\n",
       "   'age': 20.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.001,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.976,\n",
       "    'sadness': 0.02,\n",
       "    'surprise': 0.002},\n",
       "   'blur': {'blurLevel': 'medium', 'value': 0.25},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.65},\n",
       "   'noise': {'noiseLevel': 'medium', 'value': 0.5},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.09,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 0.99},\n",
       "     {'color': 'red', 'confidence': 0.99},\n",
       "     {'color': 'other', 'confidence': 0.32},\n",
       "     {'color': 'blond', 'confidence': 0.16},\n",
       "     {'color': 'black', 'confidence': 0.03},\n",
       "     {'color': 'gray', 'confidence': 0.03},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '7b7cc49e-a4c8-4901-9156-4ffd0f73dc0c',\n",
       "  'faceRectangle': {'top': 116, 'left': 524, 'width': 67, 'height': 67},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': -2.1, 'roll': 15.4, 'yaw': 15.1},\n",
       "   'gender': 'male',\n",
       "   'age': 23.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.964,\n",
       "    'sadness': 0.0,\n",
       "    'surprise': 0.036},\n",
       "   'blur': {'blurLevel': 'medium', 'value': 0.35},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.58},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.19},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.09,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'red', 'confidence': 0.99},\n",
       "     {'color': 'brown', 'confidence': 0.98},\n",
       "     {'color': 'other', 'confidence': 0.55},\n",
       "     {'color': 'black', 'confidence': 0.15},\n",
       "     {'color': 'blond', 'confidence': 0.1},\n",
       "     {'color': 'gray', 'confidence': 0.01},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}},\n",
       " {'faceId': '30cab167-e03a-4ba5-b0e8-0c490fa83dcb',\n",
       "  'faceRectangle': {'top': 130, 'left': 687, 'width': 66, 'height': 66},\n",
       "  'faceAttributes': {'smile': 0.0,\n",
       "   'headPose': {'pitch': 5.6, 'roll': -10.2, 'yaw': -4.4},\n",
       "   'gender': 'male',\n",
       "   'age': 20.0,\n",
       "   'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1},\n",
       "   'glasses': 'NoGlasses',\n",
       "   'emotion': {'anger': 0.0,\n",
       "    'contempt': 0.0,\n",
       "    'disgust': 0.0,\n",
       "    'fear': 0.0,\n",
       "    'happiness': 0.0,\n",
       "    'neutral': 0.994,\n",
       "    'sadness': 0.006,\n",
       "    'surprise': 0.0},\n",
       "   'blur': {'blurLevel': 'medium', 'value': 0.48},\n",
       "   'exposure': {'exposureLevel': 'goodExposure', 'value': 0.66},\n",
       "   'noise': {'noiseLevel': 'low', 'value': 0.14},\n",
       "   'makeup': {'eyeMakeup': True, 'lipMakeup': True},\n",
       "   'accessories': [],\n",
       "   'occlusion': {'foreheadOccluded': False,\n",
       "    'eyeOccluded': False,\n",
       "    'mouthOccluded': False},\n",
       "   'hair': {'bald': 0.06,\n",
       "    'invisible': False,\n",
       "    'hairColor': [{'color': 'brown', 'confidence': 1.0},\n",
       "     {'color': 'red', 'confidence': 0.75},\n",
       "     {'color': 'black', 'confidence': 0.71},\n",
       "     {'color': 'other', 'confidence': 0.18},\n",
       "     {'color': 'blond', 'confidence': 0.09},\n",
       "     {'color': 'gray', 'confidence': 0.03},\n",
       "     {'color': 'white', 'confidence': 0.0}]}}}]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import requests\n",
    "subscription_key = \"4f253843772f42e89e959977f6149561\" \n",
    "assert subscription_key\n",
    "face_api_url = 'https://face-ozl.cognitiveservices.azure.com/face/v1.0/detect'\n",
    "\n",
    "\n",
    "image_url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604257867460&di=4b2bcbf2f2ec8fbdc93ee6f79c034ab2&imgtype=0&src=http%3A%2F%2Fpic.xiami.net%2Fimages%2Fartistlogo%2F32%2F15216234237032.jpg'\n",
    "\n",
    "headers = {'Ocp-Apim-Subscription-Key': subscription_key}\n",
    "\n",
    "\n",
    "params = {\n",
    "    'returnFaceId': 'true',\n",
    "    'returnFaceLandmarks': 'false',\n",
    "    'detectionModel':'detection_01',\n",
    "    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',\n",
    "}\n",
    "\n",
    "response = requests.post(face_api_url, params=params,\n",
    "                         headers=headers, json={\"url\": image_url})\n",
    "results=response.json()\n",
    "results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[0]['faceAttributes']['smile']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'male'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[0]['faceAttributes']['gender']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20.0"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[0]['faceAttributes']['age']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'color': 'brown', 'confidence': 0.99},\n",
       " {'color': 'red', 'confidence': 0.99},\n",
       " {'color': 'other', 'confidence': 0.32},\n",
       " {'color': 'blond', 'confidence': 0.16},\n",
       " {'color': 'black', 'confidence': 0.03},\n",
       " {'color': 'gray', 'confidence': 0.03},\n",
       " {'color': 'white', 'confidence': 0.0}]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[0]['faceAttributes']['hair']['hairColor']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "face_01=dict(glasses='NoGlasses',gender='male',age='23',smile='0.0',hairColor=[{'color': 'red', 'confidence': 0.99},\n",
    "     {'color': 'brown', 'confidence': 0.98},\n",
    "     {'color': 'other', 'confidence': 0.55},\n",
    "     {'color': 'black', 'confidence': 0.15},\n",
    "     {'color': 'blond', 'confidence': 0.1},\n",
    "     {'color': 'gray', 'confidence': 0.01},\n",
    "     {'color': 'white', 'confidence': 0.0}])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'glasses': 'NoGlasses',\n",
       " 'gender': 'male',\n",
       " 'age': '23',\n",
       " 'smile': '0.0',\n",
       " 'hairColor': [{'color': 'red', 'confidence': 0.99},\n",
       "  {'color': 'brown', 'confidence': 0.98},\n",
       "  {'color': 'other', 'confidence': 0.55},\n",
       "  {'color': 'black', 'confidence': 0.15},\n",
       "  {'color': 'blond', 'confidence': 0.1},\n",
       "  {'color': 'gray', 'confidence': 0.01},\n",
       "  {'color': 'white', 'confidence': 0.0}]}"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'NoGlasses'"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[1]['faceAttributes']['glasses']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[1]['faceAttributes']['smile']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "23.0"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[1]['faceAttributes']['age']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'male'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[1]['faceAttributes']['gender']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'color': 'red', 'confidence': 0.99},\n",
       " {'color': 'brown', 'confidence': 0.98},\n",
       " {'color': 'other', 'confidence': 0.55},\n",
       " {'color': 'black', 'confidence': 0.15},\n",
       " {'color': 'blond', 'confidence': 0.1},\n",
       " {'color': 'gray', 'confidence': 0.01},\n",
       " {'color': 'white', 'confidence': 0.0}]"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[1]['faceAttributes']['hair']['hairColor']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "face_02=dict(glasses='NoGlasses',gender='male',age='20',smile='0.0',hairColor=[{'color': 'brown', 'confidence': 1.0},\n",
    "     {'color': 'red', 'confidence': 0.75},\n",
    "     {'color': 'black', 'confidence': 0.71},\n",
    "     {'color': 'other', 'confidence': 0.18},\n",
    "     {'color': 'blond', 'confidence': 0.09},\n",
    "     {'color': 'gray', 'confidence': 0.03},\n",
    "     {'color': 'white', 'confidence': 0.0}])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'glasses': 'NoGlasses',\n",
       " 'gender': 'male',\n",
       " 'age': '20',\n",
       " 'smile': '0.0',\n",
       " 'hairColor': [{'color': 'brown', 'confidence': 1.0},\n",
       "  {'color': 'red', 'confidence': 0.75},\n",
       "  {'color': 'black', 'confidence': 0.71},\n",
       "  {'color': 'other', 'confidence': 0.18},\n",
       "  {'color': 'blond', 'confidence': 0.09},\n",
       "  {'color': 'gray', 'confidence': 0.03},\n",
       "  {'color': 'white', 'confidence': 0.0}]}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "face_02"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.0"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[2]['faceAttributes']['smile']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20.0"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[2]['faceAttributes']['age']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'NoGlasses'"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[0]['faceAttributes']['glasses']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'male'"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[0]['faceAttributes']['gender']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[{'color': 'brown', 'confidence': 0.99},\n",
       " {'color': 'red', 'confidence': 0.99},\n",
       " {'color': 'other', 'confidence': 0.32},\n",
       " {'color': 'blond', 'confidence': 0.16},\n",
       " {'color': 'black', 'confidence': 0.03},\n",
       " {'color': 'gray', 'confidence': 0.03},\n",
       " {'color': 'white', 'confidence': 0.0}]"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "results[0]['faceAttributes']['hair']['hairColor']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
